from django.contrib import admin
from apps.generate_secret.models import AppSecret

@admin.register(AppSecret)
class AppSecretAdmin(admin.ModelAdmin):
    """
    应用秘钥管理后台
    """
    list_display = ['app_id', 'app_name', 'status', 'create_time', 'update_time']
    list_filter = ['status', 'is_delete', 'create_time']
    search_fields = ['app_id', 'app_name', 'remark']
    readonly_fields = ['app_secret', 'create_time', 'update_time']
    ordering = ['-create_time']
    
    fieldsets = (
        ('基本信息', {
            'fields': ('app_id', 'app_secret', 'app_name', 'status')
        }),
        ('其他信息', {
            'fields': ('remark', 'is_delete')
        }),
        ('时间信息', {
            'fields': ('create_time', 'update_time', 'create_by', 'update_by'),
            'classes': ('collapse',)
        }),
    )
    
    def get_queryset(self, request):
        """只显示未删除的记录"""
        return super().get_queryset(request).filter(is_delete=False)
    
    def has_delete_permission(self, request, obj=None):
        """禁用物理删除，只允许逻辑删除"""
        return False
